home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / SIDIS098.ZIP / USERCTRL / MAILPROC.CMD < prev    next >
Encoding:
Text File  |  1996-04-14  |  11.8 KB  |  385 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*  REXX Mail processor                                                 */
  4. /*                                                                      */
  5. /* (C) 1996, Axel Mueller (amueller@stargate.rz.fh-offenburg.de)        */
  6. /*     Version 0.90    04.03.96                                         */
  7. /************************************************************************/
  8.  
  9. parse arg MailInFile
  10.  
  11. call on error
  12.  
  13.  
  14. /************************************************************************/
  15. /*                                                                      */
  16. /* Setup                                                                */
  17. /*                                                                      */
  18. /************************************************************************/
  19.  
  20.  
  21. True            = 1
  22. False        = 0
  23.  
  24.  
  25. /**************/
  26. /*   setup    */
  27. /**************/
  28.  
  29. ETCPath                = value('ETC',,'OS2ENVIRONMENT')
  30. MailOutFile            = left(MailInFile, (length(MailInFile)-4))'.rsp'
  31. LogFile                = ETCPath'\mailproc.log'
  32. ContactAddress        = 'amueller@stargate.rz.fh-offenburg.de'
  33. MailProcessorUser    = 'mail-processor'
  34. MailProcessorName    = '(Mail-Processor)'
  35. Hostname                = value('HOSTNAME',,'OS2ENVIRONMENT')
  36.  
  37. ResolvFile            = ETCPath'\resolv'
  38. Line = linein(ResolvFile)
  39. do while (left(Line,6) <> 'domain')
  40.     Line = linein(ResolvFile)
  41. end
  42. rc = lineout(ResolvFile)
  43. parse value Line with dummy Domain
  44.  
  45. HostDomain            = Hostname'.'Domain
  46.  
  47.  
  48.  
  49. /*#################################################*/
  50. /*#              main routine                     #*/
  51. /*#################################################*/
  52.  
  53. Line = linein(MailInFile)
  54. do while (left(Line,8) <> 'Subject:')
  55.     Line = linein(MailInFile)
  56. end
  57. rc = lineout(MailInFile)
  58.  
  59. parse value Line with Subject User Password CommandArguments
  60. parse value CommandArguments with Command Argument1 Argument2
  61.  
  62. if User=="HELP" | User=="help" then
  63.     Command = "HELP"
  64. parse upper value Command with Command
  65.  
  66.  
  67. Line = linein(MailInFile)
  68. do while (left(Line,5) <> 'From:')
  69.     Line = linein(MailInFile)
  70. end
  71. rc = lineout(MailInFile)
  72.  
  73. parse value Line with From ResponseAddress ResponseName
  74.  
  75. call log('Received mail 'Line)
  76.  
  77.  
  78. select
  79.     when ((Command='CHANGE_PASSWORD') | (Command='C_P')) & (Argument2=="") then
  80.         call change_password
  81.     when ((Command='FORWARD_MAIL') | (Command='F_M')) & (Argument2=="") then
  82.         call forward_mail('0')
  83.     when ((Command='FORWARD_COPY') | (Command='F_C')) & (Argument2=="") then
  84.         call forward_mail('1')
  85.     when ((Command='STOP_FORWARD') | (Command='S_F')) & (Argument1=="") & (Argument2=="") then
  86.         call stop_forward
  87.     when Command='HELP' then
  88.         call help
  89.     otherwise
  90.         call unknown_command
  91. end
  92.  
  93. call log('Finished mail processing')
  94.  
  95.  
  96. exit
  97.  
  98.  
  99. /*#################################################*/
  100. /*#          mail processor commands              #*/
  101. /*#################################################*/
  102.  
  103.  
  104. /*****************************/
  105. /* change_password           */
  106. /*****************************/
  107.  
  108. change_password:
  109.  
  110.     call log('... password change request')
  111.     if (RxPrfCheckPassword(User, Password)) then
  112.         do
  113.          rc = RxPrfSetPassword(User, Argument1)
  114.          call write_mail_header
  115.          call write_robot_header
  116.          rc = lineout(MailOutFile, '*** Password has been successfully changed.')
  117.          rc = lineout(MailOutFile, '*** Do not forget your new password in order to be able to')
  118.          rc = lineout(MailOutFile, '*** login via modem and retrieve mails.')
  119.          call write_contact
  120.          rc = lineout(MailOutFile)
  121.          call log('... password has been changed')
  122.         end
  123.     else
  124.         do
  125.          call refuse_action
  126.          call write_contact
  127.          rc = lineout(MailOutFile)
  128.         end
  129.  
  130.     return
  131.  
  132.  
  133.  
  134. /*****************************/
  135. /* forward_mail              */
  136. /*****************************/
  137.  
  138. forward_mail:
  139.  
  140.     parse arg ForwardCopy
  141.  
  142.     call log('... mail forward request')
  143.     if (RxPrfCheckPassword(User, Password)) then
  144.         do
  145.          call write_mail_header
  146.          call write_robot_header
  147.          OwnAddress = User'@'HostDomain
  148.          if(Argument1 <> OwnAddress) then
  149.              do
  150.               rc = RxPrfSetForwardAddress(User, Argument1, ForwardCopy)
  151.               rc = lineout(MailOutFile, '*** Mail forwarding has been activated.')
  152.               if (ForwardCopy == 1) then
  153.                 do
  154.                   rc = lineout(MailOutFile, '*** A copy of every incoming mail will be forwarded to 'Argument1 )
  155.                   rc = lineout(MailOutFile, '*** The original mails will be keep for POP3 retrieval on this system.' )
  156.                   call log('... copy forward has been activated')
  157.                 end
  158.               else
  159.                 do
  160.                   rc = lineout(MailOutFile, '*** Every incoming mail will be forwarded to 'Argument1 )
  161.                   rc = lineout(MailOutFile, '*** No incoming mail be kept on this system.' )
  162.                   call log('... mail forward has been activated')
  163.                 end
  164.               call write_contact
  165.               rc = lineout(MailOutFile)
  166.              end
  167.          else
  168.              do
  169.               rc = lineout(MailOutFile, '*** Mail forwarding has NOT been activated.')
  170.               rc = lineout(MailOutFile, '*** The forward address specified would create a loop.')
  171.               call write_contact
  172.               rc = lineout(MailOutFile)
  173.               call log('... forward has not been activated in order to avoid loop')
  174.              end
  175.         end
  176.     else
  177.         do
  178.          call refuse_action
  179.          call write_contact
  180.          rc = lineout(MailOutFile)
  181.         end
  182.  
  183.     return
  184.  
  185.  
  186.  
  187. /*****************************/
  188. /* stop_forward              */
  189. /*****************************/
  190.  
  191. stop_forward:
  192.  
  193.     call log('... stop forward request')
  194.     if (RxPrfCheckPassword(User, Password)) then
  195.         do
  196.          rc = RxPrfSetForwardAddress(User, "", '0')
  197.          call write_mail_header
  198.          call write_robot_header
  199.          rc = lineout(MailOutFile, '*** Mail forwarding has been deactivated.')
  200.          call write_contact
  201.          rc = lineout(MailOutFile)
  202.          call log('... mail forward has been deactivated')
  203.         end
  204.     else
  205.         do
  206.          call refuse_action
  207.          call write_contact
  208.          rc = lineout(MailOutFile)
  209.         end
  210.  
  211.     return
  212.  
  213.  
  214.  
  215. /*****************************/
  216. /* help                      */
  217. /*****************************/
  218.  
  219. help:
  220.  
  221.     call write_mail_header
  222.     call write_robot_header
  223.     call write_help
  224.     call write_contact
  225.     rc = lineout(MailOutFile)
  226.     call log('... help requested has been answered')
  227.  
  228.     return
  229.  
  230.  
  231.  
  232. /*****************************/
  233. /* unknown_command           */
  234. /*****************************/
  235.  
  236. unknown_command:
  237.  
  238.     call write_mail_header
  239.     call write_robot_header
  240.     rc = lineout(MailOutFile, '*** Command/Parameter error: 'CommandArguments)
  241.     rc = lineout(MailOutFile, '')
  242.     call write_help
  243.     call write_contact
  244.     rc = lineout(MailOutFile, '   ----- Original message follows -----')
  245.     rc = lineout(MailOutFile, '')
  246.     call write_original_mail
  247.     rc = lineout(MailOutFile)
  248.     call log('... command/parameter error: 'CommandArguments)
  249.  
  250.     return
  251.  
  252.  
  253.  
  254. /*#################################################*/
  255. /*#              sub procedures                   #*/
  256. /*#################################################*/
  257.  
  258.  
  259. /*****************************/
  260. /* write_mail_header         */
  261. /*****************************/
  262.  
  263. write_mail_header:
  264.  
  265.     rc = lineout(MailOutFile, 'Return-Path: 'MailProcessorUser'@'HostDomain' 'MailProcessorName)
  266.     rc = lineout(MailOutFile, 'From: 'MailProcessorUser'@'HostDomain' 'MailProcessorName)
  267.     rc = lineout(MailOutFile, 'Subject: Response for request')
  268.     if ResponseName=="" then
  269.         rc = lineout(MailOutFile, 'To: 'ResponseAddress)
  270.     else
  271.         rc = lineout(MailOutFile, 'To: 'ResponseAddress' 'ResponseName)
  272.  
  273.     return
  274.  
  275.  
  276. /*****************************/
  277. /* write_robot_header        */
  278. /*****************************/
  279.  
  280. write_robot_header:
  281.  
  282.     rc = lineout(MailOutFile, 'This mail was created by an automatic mail processor.')
  283.     rc = lineout(MailOutFile, 'PLEASE DO NOT REPLY TO THIS MAIL.')
  284.     rc = lineout(MailOutFile, '')
  285.  
  286.     return
  287.  
  288.  
  289. /*****************************/
  290. /* write_contact             */
  291. /*****************************/
  292.  
  293. write_contact:
  294.  
  295.     rc = lineout(MailOutFile, '')
  296.     rc = lineout(MailOutFile, 'If you have any questions, suggestions or problems - please contact:')
  297.     rc = lineout(MailOutFile, ContactAddress)
  298.     rc = lineout(MailOutFile, '')
  299.  
  300.     return
  301.  
  302.  
  303.  
  304. /*****************************/
  305. /* write_help                */
  306. /*****************************/
  307.  
  308. write_help:
  309.  
  310.     rc = lineout(MailOutFile, '***********************************************************************')
  311.     rc = lineout(MailOutFile, '*               = SYNTAX FOR MAIL PROCESSOR v0.98 =                   *')
  312.     rc = lineout(MailOutFile, '* (C) Axel Mueller, 1996 (amueller@stargate.rz.fh-offenburg.de)       *')
  313.     rc = lineout(MailOutFile, '*                                                                     *')
  314.     rc = lineout(MailOutFile, '* All commands must be given in the SUBJECT!                          *')
  315.     rc = lineout(MailOutFile, '* Commands and parameter(s) must be separated by SPACE!               *')
  316.     rc = lineout(MailOutFile, '* All commands start with <user> <password> and are followd by        *')
  317.     rc = lineout(MailOutFile, '* <command>     and    <parameter(s)>                                 *')
  318.     rc = lineout(MailOutFile, '*                                                                     *')
  319.     rc = lineout(MailOutFile, '* change_password      <new password>                                 *')
  320.     rc = lineout(MailOutFile, '* forward_mail         <forward address>                              *')
  321.     rc = lineout(MailOutFile, '* forward_copy         <forward address>                              *')
  322.     rc = lineout(MailOutFile, '* stop_forward                                                        *')
  323.     rc = lineout(MailOutFile, '*                                                                     *')
  324.     rc = lineout(MailOutFile, '* Instead of the commands above you can use the following short cuts: *')
  325.     rc = lineout(MailOutFile, '* <command>            <short cut>                                    *')
  326.     rc = lineout(MailOutFile, '*                                                                     *')
  327.     rc = lineout(MailOutFile, '* change_password      c_p                                            *')
  328.     rc = lineout(MailOutFile, '* forward_mail         f_m                                            *')
  329.     rc = lineout(MailOutFile, '* forward_copy         f_c                                            *')
  330.     rc = lineout(MailOutFile, '* stop_forward         s_f                                            *')
  331.     rc = lineout(MailOutFile, '*                                                                     *')
  332.     rc = lineout(MailOutFile, '* You will receive a confirmation mail immediately after your         *')
  333.     rc = lineout(MailOutFile, '* mail has been received by the mail processor.                       *')
  334.     rc = lineout(MailOutFile, '*                                                                     *')
  335.     rc = lineout(MailOutFile, '***********************************************************************')
  336.     
  337.     return
  338.  
  339.  
  340.  
  341. /*****************************/
  342. /* write_original_mail       */
  343. /*****************************/
  344.  
  345. write_original_mail:
  346.  
  347.     MailInFilePos = 0
  348.     MailInFileSize = stream(MailInFile, 'c', 'query size')
  349.     do while (MailInFilePos<MailInFileSize)
  350.         rc = lineout(MailOutFile, Line)
  351.         Line = linein(MailInFile)
  352.         MailInFilePos=MailInFilePos+length(Line)+1
  353.     end
  354.     rc = lineout(MailInFile)
  355.  
  356.     return
  357.  
  358.  
  359. /*****************************/
  360. /* refuse_action             */
  361. /*****************************/
  362.  
  363. refuse_action:
  364.  
  365.     call write_mail_header
  366.     call write_robot_header
  367.     rc = lineout(MailOutFile, '*** You are not authorized for the requested action!')
  368.     call log('... no authorization for requested action')
  369.  
  370.     return
  371.  
  372.  
  373.  
  374. /*****************************/
  375. /* log                       */
  376. /*****************************/
  377.  
  378. log:
  379.  
  380.     parse arg LogString
  381.  
  382.     rc = lineout( LogFile, date(european)' 'time(normal)'' LogString )
  383.  
  384.     return
  385.